//关于file的上传文件的js
~function(){
	$('.surfile').on('change',function(){
		check($(this))
	})
	$('.ju-btns2').on('click',function(){
		
	})
	function check(obj){
		var maxsize = 20*1024*1024;//20M 
		var size=0;
		var src=obj.val();
		var cns=src.split('\\');
		var cnt=src.split(".");
		
		var val=cnt[cnt.length-1].toLowerCase(); //后缀
		var vals=cns[cns.length-1]; //上传文件的名称
		
		var arr=['xls','xlsx','et','doc','docx','pdf','zip','rar','7z','iso','ace','cab','uue','.jar','tar','png','jpg']
		var arr1=['xls','xlsx','et'];
		var arr2=['doc','docx'];
		var arr3=['pdf'];
		var arr4=['zip','rar','7z','iso','ace','cab','uue','jar','tar'];
		
	
		var  browserCfg = {};  
		var regt=new RegExp('.'+ val)
		
        var ua = window.navigator.userAgent;  
        if (ua.search(/MSIE/)>=1){  
            browserCfg.ie = true;  
        }else if(ua.search(/Firefox/)>=1){  
            browserCfg.firefox = true;  
        }else if(ua.search(/Chrome/)>=1){  
            browserCfg.chrome = true;  
        } 
		var ua = window.navigator.userAgent; 
		if(browserCfg.firefox || browserCfg.chrome ){  
            size = obj.get(0).files[0].size;  
        }else if(browserCfg.ie){  
            size = obj.get(0).fileSize;  
        }else{  
            alert('浏览器不支持，请使用谷歌，火狐，ie');  
            return;  
        }  
		if(size>maxsize){
			alert('文件不能大于20M');
			return
		}else if(arr.join('').search(regt)==-1){
			alert('上传文件格式支持Word、excel、PDF、压缩包四种格式')
		}else{
			obj.parents('.filed').children('.ulnamepac').html(vals);
			obj.parents('.upbtn').children('.namehide').val(vals);
			obj.parents('.upbtn').children('span').html('修改').addClass('change');
		}
	}
}()
// 上传图片的
	jQuery.fn.extend({
	    uploadPreview: function (opts) {
	        var _self = this,
	            _this = $(this);
	        opts = jQuery.extend({
	            Img: "ImgPr",
	            Width: 100,
	            Height: 100,
	            ImgType: ["gif", "jpeg", "jpg", "bmp", "png"],
	            Callback: function () {}
	        }, opts || {});
	        _self.getObjectURL = function (file) {
	            var url = null;
	            if (window.createObjectURL != undefined) {
	                url = window.createObjectURL(file)
	            } else if (window.URL != undefined) {
	                url = window.URL.createObjectURL(file)
	            } else if (window.webkitURL != undefined) {
	                url = window.webkitURL.createObjectURL(file)
	            }
	            return url
	        };
	        _this.change(function () {
	            if (this.value) {
	                if (!RegExp("\.(" + opts.ImgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
	                    alert("选择文件错误,图片类型必须是" + opts.ImgType.join("，") + "中的一种");
	                    this.value = "";
	                    return false
	                }
	               
	                    try {
	                        $("#" + opts.Img).attr('src', _self.getObjectURL(this.files[0]))
	                    } catch (e) {
	                        var src = "";
	                        var obj = $("#" + opts.Img);
	                        var div = obj.parent("div")[0];
	                        _self.select();
	                        if (top != self) {
	                            window.parent.document.body.focus()
	                        } else {
	                            _self.blur()
	                        }
	                        src = document.selection.createRange().text;
	                        document.selection.empty();
	                        obj.hide();
	                        obj.parent("div").css({
	                            'filter': 'progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)',
	                            'width': 200 + 'px',
	                            'height': 200 + 'px'
	                        });
	                        div.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = src
	                    }
	                
	                opts.Callback()
	            }
	        })
	    }
	});